package com.tjp.eight.views;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Point;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.tjp.eight.R;

/**
 * Created by Administrator on 2017/2/28.
 */

public class ShareDialog extends Dialog implements View.OnClickListener {
    private Context mContext;
    private LayoutInflater inflater;
    private WindowManager.LayoutParams lp;
    private ImageView ivWx;
    private ImageView ivWxCircle;
    private ImageView ivQQZone;
    private ImageView ivQQ;
    private ImageView ivCollection;
    private ImageView ivReport;
    private LinearLayout llCollection;
    private LinearLayout llReport;
    private ImageView ivDismiss;
    private OnClickType onClickType;
    public static final int TYPE_WX = 0x00;
    public static final int TYPE_WX_CIRCLE = 0x01;
    public static final int TYPE_QQ = 0x02;
    public static final int TYPE_QQ_ZONE = 0x03;
    public static final int TYPE_COLLECTION = 0x04;
    public static final int TYPE_REPORT = 0x05;
    public static final int TYPE_DISMISS = 0x06;

    public ShareDialog(final Context context) {
        super(context, R.style.Dialog);

        this.mContext = context;

        inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.share_dialog_layout, null);

        ivWx = (ImageView) layout.findViewById(R.id.iv_wx);
        ivWxCircle = (ImageView) layout.findViewById(R.id.iv_wx_circle);
        ivQQ = (ImageView) layout.findViewById(R.id.iv_qq);
        ivQQZone = (ImageView) layout.findViewById(R.id.iv_qq_zone);
        ivCollection = (ImageView) layout.findViewById(R.id.iv_collection);
        ivReport = (ImageView) layout.findViewById(R.id.iv_report);
        llReport = (LinearLayout) layout.findViewById(R.id.ll_report);
        llCollection = (LinearLayout) layout.findViewById(R.id.ll_collection);
        ivDismiss = (ImageView) layout.findViewById(R.id.iv_dismiss);

        ivWx.setOnClickListener(this);
        ivWxCircle.setOnClickListener(this);
        ivQQ.setOnClickListener(this);
        ivQQZone.setOnClickListener(this);
        ivCollection.setOnClickListener(this);
        ivReport.setOnClickListener(this);
        ivDismiss.setOnClickListener(this);

        setContentView(layout);

        // 设置window属性
        lp = getWindow().getAttributes();
        Display display = getWindow().getWindowManager().getDefaultDisplay();
        Point point = new Point();
        display.getSize(point);
        lp.width = point.x;
        lp.gravity = Gravity.CENTER | Gravity.CENTER_HORIZONTAL;
        lp.alpha = 1.0f;
        getWindow().setAttributes(lp);
        setCanceledOnTouchOutside(true);
    }

    @Override
    public void show() {
        super.show();
    }

    @Override
    public void dismiss() {
        super.dismiss();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_wx:
                setType(TYPE_WX);
                break;
            case R.id.iv_wx_circle:
                setType(TYPE_WX_CIRCLE);
                break;
            case R.id.iv_qq:
                setType(TYPE_QQ);
                break;
            case R.id.iv_qq_zone:
                setType(TYPE_QQ_ZONE);
                break;
            case R.id.iv_collection:
                setType(TYPE_COLLECTION);
                break;
            case R.id.iv_report:
                setType(TYPE_REPORT);
                break;
            case R.id.iv_dismiss:
                dismiss();
                setType(TYPE_DISMISS);
                break;
        }
    }

    private void setType(int type) {
        if (onClickType != null) {
            onClickType.clickType(type);
        }
    }

    public void setOnClickType(OnClickType onClickType) {
        this.onClickType = onClickType;
    }

    public interface OnClickType {
        void clickType(int type);
    }

    public void setRCVisible(int visible) {
        ivCollection.setVisibility(visible);
        ivReport.setVisibility(visible);
        llReport.setVisibility(visible);
        llCollection.setVisibility(visible);
    }
}
